import { useCallback } from 'react';
import { DynamicCrudPage } from '@/components';
import type { TableConfig } from '@/components/DynamicTable/types';
import { getTableConfigByCode } from '@/api/tableConfig';
import { transformTableConfig } from '@/utils/tableConfigTransform';
import { transformEditData, transformSubmitData } from '@/utils/formDataTransform';
import { getAuditLogs} from './api';

const AuditLogManagement = () => {
  const fetchConfigApi = useCallback(async (): Promise<TableConfig> => {
    const configRecord = await getTableConfigByCode('audit_logs');
    if (!configRecord) {throw new Error('审计日志表格配置不存在');}
    return transformTableConfig(configRecord);
  }, []);

  return (
    <DynamicCrudPage
      fetchConfigApi={fetchConfigApi}
      fetchApi={getAuditLogs}
      transformEditData={transformEditData}
      transformFormData={(data, mode) => transformSubmitData(data)}
      title="审计日志"
    />
  );
};

export default AuditLogManagement;
